import math
import time
w = 80
h = 80
WIDTH = 800
HEIGHT = 800

def genMatrix(rows,cols):
    matrix = [[0 for col in range(cols)] for row in range(rows)]  
    for i in range(rows):  
        for j in range(cols):  
            matrix[i][j]
    return matrix

def testSnake():
    number = 5
    matrix = genMatrix(number, number)
    i = 0
    j = 0
    total = matrix[i][j] = 1
    while(total < number * number):
        while(j + 1 < number and matrix[i][j + 1] == 0): 
            total += 1
            j += 1
            matrix[i][j] = total
        while(i + 1 < number and matrix[i + 1][j] == 0):
            total += 1
            i += 1
            matrix[i][j] = total
        while(j > 0 and matrix[i][j - 1] == 0): 
            total += 1
            j -= 1
            matrix[i][j] = total
        while(i + 1 > 0 and matrix[i - 1][j] == 0): 
            total += 1
            i -= 1
            matrix[i][j] = total
    for i in range(number):  
        for j in range(number):
            print ('\t%d ' % matrix[i][j], end='')
        print('\n')
    return matrix[:]

    

matrix = testSnake()
print("matrix",matrix)

def make_list(size,num):
    lst = []
    for j in range(0,len(matrix)):    
        for i in matrix[j]:
            blockx = (i % int(math.sqrt(num)))* size + 0.5 * size
            blocky = (i // int(math.sqrt(num))) * size + 0.5 * size
            a = (blockx,blocky)
            lst.append(a[:])
    return lst[:]

lst = make_list(80,25)
print(lst)

it = 0
def update():
    global it
    rc = Rect((lst[it][0],lst[it][1]),(w,h))
    screen.draw.filled_rect(rc,(40,200,40))
    it += 1
    time.sleep(1)
